#!/usr/bin/python
#coding=utf-8
#fileName:contactAction.py
#contact 入口 

import sys
import contact

if __name__ == '__main__':
    filename = raw_input("Please input your contact Name")
    if len(filename) == 0: exit()
    contactData = contact.Contact(filename+'.dat')
    while True:
        print '''Welcome use MyContact \n
        Please select A Menu\n
        1. List all contacts\n
        2. Add a name to contact\n
        3. Delete a name of contact\n
        4. Exit\n'''
        
        act = int(raw_input())
        
        if act == 1: # list all
            list = contactData.listAll();
            print "name\tphone"
            if len(list) > 0 :
                for name,phone in list.items():
                    print  name,'\t', phone
            else:
                print 'no contact!'
            raw_input('Press any key back to Menu\n')
            continue;
        
        elif act == 2: # add
            name = raw_input('input name\n')
            phone = raw_input('input phone\n')
            contactData.add(name,phone)
            raw_input('Press any key back to Menu\n')
            continue;
        
        elif act == 3: # del
            name = raw_input('input the name you are going to delete\n')
            contactData.delContact(name)
            raw_input('Press any key back to Menu\n')
            continue;
        
        elif act==4: # exit
            break;
             
    